package com.bj.zspace.bytebuddy.bbtest;

import com.bj.zspace.bytebuddy.normal_test.Service;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.SuperMethodCall;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.matcher.ElementMatchers;

import java.io.File;

/**
 * 拦截构造方法
 **/
public class ConstructClass {

    public static void main(String[] args) throws Exception{

        String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        DynamicType.Unloaded<Service> unloaded = new ByteBuddy()
            .subclass(Service.class).name("a.b.SubService")
            // 任意的构造方法
            .constructor(ElementMatchers.any())
            // 修改入参 withBinder得方法
            .intercept(SuperMethodCall.INSTANCE.andThen(null)) // 构造方法使用, error: todo
            .make();

        unloaded.saveIn(new File(path));
    }

}
